var app = new Vue({
    el: '.register-container',
    data(){
        return {
            formInline:{
                isagree:false, //是否同意协议
            },
            inputemail:'',
            inputpwd:'',
            inputrepwd:'',
            prompt:{
                email:'',
                pwd:'',
                repwd:'',
                protocol:''
            }
        }
    },
    created() {
        this.setRem(28.43);
        // this.fontSize(53);
    },
    methods: {
        prompts(){
            document.getElementsByClassName("prompt")[0].style.display = "none";
            document.getElementsByClassName("prompt1")[0].style.display = "none";
            document.getElementsByClassName("prompt2")[0].style.display = "none";
            document.getElementsByClassName("prompt3")[0].style.display = "none";
        },
        setRem(itemNum) {
            //设置字体rem
            let size = itemNum || 38;
            window.onresize = remSize;
            remSize();
            function remSize() {
                let html = document.getElementsByTagName("html")[0],
                    w = html.clientWidth;
                w = w > 768 ? 768 : w;
                html.style.fontSize = w / size + "px";
            }
        },
        fontSize(itemnum) {
            let html = document.getElementsByTagName("html")[0];
            let a = html.style.fontSize;
        },
        register(){
            if(this.inputemail == "" || this.inputemail == null){
                this.prompt.email = "邮箱不能为空"
                document.getElementsByClassName("prompt")[0].style.display = "block";
                let timer=setInterval(() => {
                    this.prompts()
                    clearInterval(timer)
                    timer=null
                },2000)
                return
            }else if(this.inputpwd == "" || this.inputpwd == null){
                this.prompt.pwd = "密码不能为空"
                document.getElementsByClassName("prompt1")[0].style.display = "block";
                let timer=setInterval(() => {
                    this.prompts()
                    clearInterval(timer)
                    timer=null
                },2000)
                return
            }else if(this.inputrepwd == "" || this.inputrepwd == null){
                this.prompt.repwd = "请输入确认密码"
                document.getElementsByClassName("prompt2")[0].style.display = "block";
                let timer=setInterval(() => {
                    this.prompts()
                    clearInterval(timer)
                    timer=null
                },2000)
                return
            }else if(this.inputpwd != this.inputrepwd){
                this.prompt.pwd = "两次密码输入不一致"
                document.getElementsByClassName("prompt1")[0].style.display = "block";
                let timer=setInterval(() => {
                    this.prompts()
                    clearInterval(timer)
                    timer=null
                },2000)
                this.inputpwd = ''
                this.inputrepwd = ''
                return
            }else if(this.formInline.isagree == false){
                this.prompt.protocol = "请勾选本站协议"
                document.getElementsByClassName("prompt3")[0].style.display = "block";
                let timer=setInterval(() => {
                    this.prompts()
                    clearInterval(timer)
                    timer=null
                },2000)
                return
            }else{
                let params = { 
                    email:this.inputemail,
                    password:this.inputpwd
                }
                axios.post('/yesUser/register',params).then(res => {
                    if(res.data.code == -10002){
                        this.prompt.email="邮箱已存在,请重新输入"
                        document.getElementsByClassName("prompt")[0].style.display = "block";
                        this.inputemail=""
                        this.inputpwd=""
                        this.inputrepwd=""
                        let timer=setInterval(() => {
                            this.prompts()
                            clearInterval(timer)
                            timer=null
                        },2000)
                        return
                    }else if(res.data.code == -10003){
                        this.prompt.protocol="注册失败，请重新注册"
                        document.getElementsByClassName("prompt3")[0].style.display = "block";
                        this.inputemail=""
                        this.inputpwd=""
                        this.inputrepwd=""
                        let timer=setInterval(() => {
                            this.prompts()
                            clearInterval(timer)
                            timer=null
                        },2000)
                        return
                    }else if(res.data.code == 200){
                        this.prompt.protocol="注册成功"
                        document.getElementsByClassName("prompt3")[0].style.display = "block";
                        this.inputemail=""
                        this.inputpwd=""
                        this.inputrepwd=""
                        let timer=setInterval(() => {
                            this.prompts()
                            clearInterval(timer)
                            timer=null
                        },2000)
                        location.href = "/m/mloading";
                        return
                    }
                })
            }
            
        }
    }
})